package top.tsyz.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.tsyz.entity.Coupon;
import top.tsyz.service.ICouponService;

import java.util.List;

/**
 * CouponController控制器
 */
@RestController
@RequestMapping("/api/coupons")
@Api(tags = "Coupon管理接口")
public class CouponController {

    @Autowired
    private ICouponService icouponservice;

    @GetMapping("/list")
    @ApiOperation("获取所有Coupon")
    public List<Coupon> list() {
        return icouponservice.list();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取Coupon")
    public Coupon getById(@PathVariable Long id) {
        return icouponservice.getById(id);
    }

    @PostMapping
    @ApiOperation("新增Coupon")
    public boolean save(@RequestBody Coupon coupon) {
        return icouponservice.save(coupon);
    }

    @PutMapping
    @ApiOperation("更新Coupon")
    public boolean update(@RequestBody Coupon coupon) {
        return icouponservice.updateById(coupon);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除Coupon")
    public boolean delete(@PathVariable Long id) {
        return icouponservice.removeById(id);
    }
}
